// com/zzyl/controller/NursingPlanController.java
package com.zzyl.controller;

import com.github.pagehelper.PageInfo;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理计划管理 API 控制器
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends  BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return 包含所有护理计划列表的 ResponseEntity
     */
    @GetMapping
    @ApiOperation(value = "查询所有护理计划", notes = "获取所有护理计划")
    public ResponseResult<List<NursingPlan>> getAllNursingPlans() {
        return success(nursingPlanService.getAllNursingPlans());
    }

    /**
     * 新增护理计划
     * @param dto 包含新增护理计划信息的 DTO 对象
     * @return 操作结果信息
     */
    @PostMapping
    @ApiOperation(value = "新增护理计划", notes = "添加护理计划。")
    public ResponseResult addNursingPlan(@RequestBody @ApiParam(value = "护理计划信息", required = true) NursingPlanDto dto) {
        nursingPlanService.addNursingPlan(dto);
        return success();
    }

    /**
     * 条件分页查询护理计划
     * @param name 护理计划名称，支持模糊查询
     * @param status 状态：0-禁用，1-启用
     * @param pageNum 当前页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @return 分页后的护理计划视图对象列表
     */
    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询护理计划", notes = "根据计划名称、状态进行模糊查询，并支持分页。", httpMethod = "GET", response = PageInfo.class)
    public ResponseResult<PageResponse<NursingPlanVo>> getNursingPlansByCondition(
            @RequestParam(required = false) @ApiParam(value = "护理计划名称（模糊查询）") String name,
            @RequestParam(required = false) @ApiParam(value = "状态：0-禁用，1-启用", allowableValues = "0,1") Integer status,
            @RequestParam(defaultValue = "1") @ApiParam(value = "当前页码", defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") @ApiParam(value = "每页大小", defaultValue = "10") Integer pageSize) {
        return success(nursingPlanService.selectByPage(name, status,pageNum,pageSize));
    }

    /**
     * 根据ID查询护理计划
     * @param id 护理计划的唯一标识符
     * @return 指定ID的护理计划对象
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询护理计划", notes = "通过护理计划的唯一ID获取其详细信息。")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@PathVariable @ApiParam(value = "护理计划ID", required = true) Long id) {
        return success(nursingPlanService.getNursingPlanById(id));
    }

    /**
     * 修改护理计划
     * @param dto 包含待更新信息的护理计划 DTO 对象，ID 必须存在
     * @return 操作结果信息
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult updateNursingPlan(@RequestBody @ApiParam(value = "护理计划更新信息", required = true) NursingPlanDto dto) {
        nursingPlanService.updateNursingPlan(dto);
        return success();
    }

    /**
     * 删除护理计划
     * @param id 要删除的护理计划的ID
     * @return 操作结果信息
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult deleteNursingPlanById(@PathVariable @ApiParam(value = "护理计划ID", required = true) Long id) {
        nursingPlanService.deleteNursingPlanById(id);
        return success();
    }

    /**
     * 启用或禁用护理计划
     * @param id 护理计划的ID
     * @param status 目标状态：1-启用，0-禁用
     * @return 操作结果信息
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理计划")
    public ResponseResult enableOrDisable(
            @PathVariable  Long id,
            @PathVariable  Byte status) {
        nursingPlanService.enableOrDisable(id, status);
        return success();
    }
}